<template>
	<view class="container">
		<view class="inventBox mt20">
			<uni-swipe-action v-for="(item, index) in inventory" :key="index" >
				<uni-swipe-action-item :options="options" @click="onClick(item.inventory_id)" @change="change">
					<view class="invent-item" @tap="counting(item.inventory_id)">
						<view class="left">
							<view class="pic"><dimg src="item.avatar"></dimg></view>
							<view class="text">
								<view class="name f32 c333 mb20">
									发起人：{{ item.user_name }}
									<block v-if="item.is_boss == 1">（老板）</block>
								</view>
								<view class="time f32 c666">{{ item.create_time | birtime}} 盘点</view>
							</view>
						</view>
						<view class="right f32 c666">
							{{ item.is_complete == 0 ? '盘点中' : '已结束' }}
							<image src="../../static/images/arrow_right.png" mode="aspectFit"></image>
						</view>
					</view>
				</uni-swipe-action-item>
			</uni-swipe-action>
		</view>
		<view style="height: 130upx;"></view>
		<view class="fiexd-add" @tap="newAdd()">
			<view class="text f32 cfff">
				<image src="../../static/images/tb_icon.png" mode="aspectFit"></image>
				新建盘点
			</view>
		</view>
	</view>
</template>

<script>
import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue';
import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue';
export default {
	components: {
		uniSwipeAction,
		uniSwipeActionItem
	},
	data() {
		return {
			inventory: [],
			options: [
				{
					text: '删除',
					style: {
						backgroundColor: '#fe6e65'
					}
				}
			]
		};
	},
	onLoad() {
		this.getinventory();
	},
	methods: {
		getinventory() {
			let that = this;
			that.$ajax('api/v1.inventory/index', {})
				.then(res => {
					if (res.code == 1) {
						that.inventory = res.result.page_list;
					}
				})
				.catch(res => {
					that.$sToast(res.message);
				});
		},
		counting(id) {
			uni.setStorageSync('id',id)
			uni.navigateTo({
				url: './keepsheet'
			});
		},
		onClick(id){
			let that=this;
			that.$ajax('api/v1.inventory/del',{
				inventory_id:id
			}).then(res=>{
				if(res.code==1){
					that.$sToast('删除成功')
					this.getinventory()
				}
			}).catch(res=>{
				that.$sToast(res.message)
			})
		},
		newAdd() {
			let that = this;
			that.$ajax('api/v1.inventory/add')
				.then(res => {
					if (res.code == 1) {
						that.$sToast('盘点成功');
						this.getinventory()
					}
				})
				.catch(res => {
					that.$sToast(res.message);
				});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f7f4f8;
}

.inventBox {
	.invent-item {
		width: 100%;
		display: flex;
		flex: 1;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		background-color: $white-background;
		padding: 35upx 30upx;
		box-sizing: border-box;
		border-bottom: 2upx #eee solid;

		.left {
			display: flex;
			flex-direction: row;
			align-items: center;
			.pic {
				image {
					width: 100upx;
					height: 100upx;
					border-radius: 50%;
					margin-right: 30upx;
				}
			}
		}
		.right {
			display: flex;
			flex-direction: row;
			align-items: center;
			image {
				width: 20upx;
				height: 35upx;
				margin-left: 30upx;
				margin-top: 4upx;
			}
		}
	}
}
.fiexd-add {
	width: 100%;
	position: fixed;
	bottom: 0;
	height: 100upx;
	line-height: 100upx;
	background-color: #249af6;

	.text {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;

		image {
			width: 36upx;
			height: 36upx;
			margin-right: 20upx;
		}
	}
}
</style>
